//
//  CollectViewController.m
//  projectA_kuaiZhui
//
//  Created by 张祎 on 15-3-21.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "CollectViewController.h"
#import "Collect_CollectionViewCell.h"
#import "historyCollectionViewCell.h"
#import "myLoadCollectionViewCell.h"
#import "UIButton+InitButton.h"

@interface CollectViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain)UICollectionView *collectView;
@property (nonatomic, retain)UIImageView *imageView;
@property (nonatomic, retain)UIButton *collectButton;
@property (nonatomic, retain)UIButton *historyButton;
@property (nonatomic, retain)UIButton *myLoadButton;
@property (nonatomic, retain)UIView *littleView;

@end

@implementation CollectViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;

}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    CGFloat width = self.view.frame.size.width;
    CGFloat height = self.view.frame.size.height;
    
    self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, width, 64 )];
    self.imageView.image = [UIImage imageNamed:@"navi_bg_1.jpg"];
    self.imageView.userInteractionEnabled = YES;
    [self.view addSubview:self.imageView];
    [_imageView release];
    
    self.collectButton = [UIButton buttonWithTitle:@"收藏" frame:CGRectMake(5, 10, 60, 40) target:self action:@selector(CollectClick:)];

    [self.imageView addSubview:self.collectButton];
    
    self.historyButton = [UIButton buttonWithTitle:@"历史" frame:CGRectMake(70, 10, 60, 40) target:self action:@selector(historyButtonClick:)];
    
    [self.imageView addSubview:self.historyButton];
    
    self.myLoadButton = [UIButton buttonWithTitle:@"本地" frame:CGRectMake(140, 10, 60, 40) target:self action:@selector(myLoadButtonClick:)];
    
    [self.imageView addSubview:self.myLoadButton];
    
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.itemSize = CGSizeMake(width , height - 64 - 49);
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.minimumLineSpacing = 0;
    
    self.collectView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 64, width, height-64-49) collectionViewLayout:flowLayout];
    self.collectView.backgroundColor = [UIColor whiteColor];
    self.collectView.delegate = self;
    self.collectView.dataSource = self;
    self.collectView.bounces = NO;
    self.collectView.pagingEnabled = YES;
    [self.view addSubview:self.collectView];
    [_collectView release];
    
  
    
}

- (void)dealloc
{
   
    [_imageView release];
    [super dealloc];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return  3;

}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
   
    if (indexPath.row == 0) {
        
        [self.collectView registerClass:[Collect_CollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
        
        Collect_CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
        cell.contentView.backgroundColor = [UIColor blackColor];
        return  cell;
        
    }else if(indexPath.row == 1)
    {
    
        [self.collectView registerClass:[historyCollectionViewCell class] forCellWithReuseIdentifier:@"reuse1"];
        
        
       historyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse1" forIndexPath:indexPath];
        cell.contentView.backgroundColor = [UIColor greenColor];
    return  cell;
    }
    else{
    
        [self.collectView registerClass:[myLoadCollectionViewCell class] forCellWithReuseIdentifier:@"reuse2"];
        
        
       myLoadCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse2" forIndexPath:indexPath];
        cell.contentView.backgroundColor = [UIColor orangeColor];
    return  cell;
    
    
    }
    
}
- (void)CollectClick:(UIButton *)button
{
  [self.collectView setContentOffset:CGPointMake(0, 0)];
}

- (void)historyButtonClick:(UIButton *)button{
    
    [self.collectView setContentOffset:CGPointMake(375, 0)];
    
}

- (void)myLoadButtonClick:(UIButton *)button{
    
    [self.collectView setContentOffset:CGPointMake(375*2, 0)];
    
}
- (void)collectionViewDidScroll:(UICollectionView *)collectionView
{
    NSLog(@"%@", NSStringFromCGPoint(self.collectView.contentOffset));
 
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
